const service = axios.create({
    baseURL:'http://localhost:8080/api/',
    timeout:5000,
    headers: {'Authorization': $.cookie("token")}
})

service.interceptors.request.use(config => {
    return config;
},error => {
    return Promise.reject();
})

service.interceptors.response.use(response => {
    if(response.status===200){
        return response.data;
    }else{
        Promise.reject();
    }
},(error) => {
    alert(error.response.data.msg);
    if(error.response.status===401){
        window.location.href = "http://localhost:8080/login";
    }
    return Promise.reject(error);
})

function axiosReq(type,url,query){
    return new Promise(resolve=>{
        let result = service[type](url,query).then(res=> {
            resolve(res);
        })
    })
}
